package com.lx.commonlib.mvp.persenter;

import java.lang.ref.WeakReference;


/**
*  类说明：基础的presenter
*  created by liuxiong on 2020/1/13
**/
public abstract class BasePresenter<T> {
    private final String TAG = "BasePresenter---";
    /***
     * view 接口的类型的弱引用
     */
    protected WeakReference<T> mViewRef;

    public BasePresenter(T view){
        mViewRef = new WeakReference<T>(view);
    }

    protected T getView() {
        return mViewRef.get();
    }

    public boolean isViewAttached() {
        return mViewRef != null && mViewRef.get() != null;
    }

    public void deattachView() {
        if (mViewRef != null) {
            mViewRef.clear();
            mViewRef = null;
        }
    }
}
